# -*- coding:utf-8 -*-
import os


def run_cmd(cmd):
    os.system("../../cmd/sh/%s" % cmd)


def out_compose_file(image, path):
    fo = open("../../../dk/ver", "r")
    v = fo.readline()
    tmp = v.split()
    ver = tmp[0]

    f = path + "docker-compose.yml"
    run_cmd("d.sh %s client %s" % (f, ver))

    restart = image["restart"]
    if restart:
        run_cmd("c.sh %s" % f)


def out_file(image):
    ver = image["ver"]

    d = "./output/client_%s/front/" % ver
    os.system("mkdir -p %simg" % d)

    out_compose_file(image, d)

    os.system("../../cmd/saveimg.sh %s client" % d)
    os.system("../../cmd/gen/gen.sh %s" % d)

    os.system("rm -f ./output/pack.sh")
    os.system("ln -s ../../../cmd/pack.sh ./output/pack.sh")


def new_out_file(image):
    d = "./output/client/front/"
    os.system("mkdir -p %simg" % d)

    out_compose_file(image, d)

    os.system("../../cmd/saveimg.sh %s client" % d)
    os.system("../../cmd/gen/gen.sh %s" % d)


def web_compose_file(image, path):
    fo = open("../../../dk/ver", "r")
    v = fo.readline()
    tmp = v.split()
    ver = tmp[0]

    f = path + "docker-compose.yml"
    run_cmd("wd.sh %s wclient %s" % (f, ver))

    restart = image["restart"]
    if restart:
        run_cmd("c.sh %s" % f)


def web_out_file(image):
    d = "./output/client/front/"
    os.system("mkdir -p %simg" % d)

    web_compose_file(image, d)

    os.system("../../cmd/saveimg.sh %s wclient" % d)
    os.system("../../cmd/gen/gen.sh %s" % d)
